﻿using System;
using FluentValidation;
using FluentValidation.Results;
using System.Collections.Generic;

namespace SilenthinkContract.Domain
{
    public class User : Versionable<int>
    {
        /// <summary>
        /// Guid
        /// </summary>
        public string Guid { get; set; }

        /// <summary>
        /// 注册来源 0为通过用户名注册，1为通过邮箱注册，2为通过手机号码注册，3为通过手机短信注册
        /// </summary>
        public int Origin { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        public string NickName { get; set; }

        /// <summary>
        /// 角色
        /// </summary>
        public string Role { get; set; }

        /// <summary>
        /// 绑定邮箱
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// 绑定手机
        /// </summary>
        public string Mobile { get; set; }

        /// <summary>
        /// 支付密码
        /// </summary>
        public string PayPassword { get; set; }

        /// <summary>
        /// 等级
        /// </summary>
        public byte Level { get; set; }

        /// <summary>
        /// 最后一次登录IP
        /// </summary>
        public string LastIpAddress { get; set; }

        /// <summary>
        /// 最后一次登录时间
        /// </summary>
        public DateTime LastLoginTime { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public UserStatus Status { get; set; }

        public virtual UserProfile UserProfile { get; set; }
        public virtual UserExtra UserExtra { get; set; }

        public static IDictionary<UserStatus, string> StatusDic
        {
            get
            {
                var dic = new Dictionary<UserStatus, string>();
                dic.Add(UserStatus.Normal, "正常");
                dic.Add(UserStatus.Locked, "锁定");
                return dic;
            }
        }

        protected override ValidationResult Validate()
        {
            var validator = new Validator<User>();
            validator.RuleFor(o => o.Name).NotEmpty().WithMessage("不能为空");

            return validator.Validate(this);
        }
    }
}